package c.c.b.a.b;

import c.c.b.a.b.a.e;
import c.c.b.a.b.a.f;
import c.c.b.a.b.b0.a;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Iterator;
import java.util.Objects;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/* compiled from: Dispatcher */
public final class q {
    public ExecutorService a;
    public final Deque<a> b = new ArrayDeque();
    public final Deque<a> c = new ArrayDeque();
    public final Deque<b0> d = new ArrayDeque();

    public final <T> void a(Deque<T> deque, T t, boolean z) {
        synchronized (this) {
            if (deque.remove(t)) {
                if (z) {
                    b();
                }
                synchronized (this) {
                    int size = this.c.size() + this.d.size();
                }
            } else {
                throw new AssertionError("Call wasn't in-flight!");
            }
        }
    }

    public final void b() {
        if (this.c.size() < 64 && !this.b.isEmpty()) {
            Iterator it = this.b.iterator();
            while (it.hasNext()) {
                a aVar = (a) it.next();
                Iterator it2 = this.c.iterator();
                if (it2.hasNext()) {
                    Objects.requireNonNull((a) it2.next());
                    throw null;
                }
                ExecutorService executorService;
                it.remove();
                this.c.add(aVar);
                synchronized (this) {
                    if (this.a == null) {
                        TimeUnit timeUnit = TimeUnit.SECONDS;
                        SynchronousQueue synchronousQueue = new SynchronousQueue();
                        byte[] bArr = e.a;
                        this.a = new ThreadPoolExecutor(0, Integer.MAX_VALUE, 60, timeUnit, synchronousQueue, new f("OkHttp Dispatcher", false));
                    }
                    executorService = this.a;
                }
                executorService.execute(aVar);
                if (this.c.size() >= 64) {
                    return;
                }
            }
        }
    }
}
